﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Collections;
public partial class Crm_Dictionary : BaseCrm
{

    public string pid = "0", pname = "", depth = "";
    List<Dukey.Model.Dictionary> list = BLL.SysTable.instance.GetList("");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["pid"]))
        {
            pid = Request.QueryString["pid"];
        }
        gvList.DataSourceID = BaseWeb.IsAccessData ? "accessdata" : "sqserverlData";
    }

    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        object o = BLL.DataBaseHelper.instance.GetSingle("Sys_Dictionary", "px", "pid=" + pid, "px desc");
        o = (o == null ? 0 : o);
        Hashtable hs = new Hashtable();
        hs.Add("pid", pid);
        hs.Add("keytext", "新键值");
        hs.Add("px", Convert.ToInt32(o) + 1);
        BLL.DataBaseHelper.instance.Insert(hs, "Sys_Dictionary");
        gvList.DataSourceID = BaseWeb.IsAccessData ? "accessdata" : "sqserverlData";
        
    }

    string str = "";
    public string GetNavLink(int id)
    {
        if (list != null)
        {
            Dukey.Model.Dictionary model = list.Find(item => item.id == id);
            if (model != null && model.pid == 0)
            {
                str = string.Format("<a class=\"nav\" href='Dictionary.aspx?pid={0}&pname={1}'>{1}</a>&gt;&gt;", model.id, model.keytext) + str;
                return str.ToString();
            }
            else if (model != null && model.pid != 0)
            {
                str = string.Format("<a class=\"nav\" href='Dictionary.aspx?pid={0}&pname={1}'>{1}</a>&gt;&gt;", model.id, model.keytext) + str;
                return GetNavLink(model.pid);
            }
            return "";
        }
        else
        {
            return "";
        }
    }
}
